package com.stock.controller;

import com.stock.service.IStockDataService;
import com.stock.service.IStockHistoryDataService;
import com.stock.service.IStockProfitDataService;
import com.stock.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stockData")
@CrossOrigin(origins = "*")
@Api(tags = "股票数据管理")
public class StockDataController {

    private final IStockDataService stockDataService;

    private final IStockHistoryDataService stockHistoryDataService;

    private final IStockProfitDataService stockProfitDataService;

    public StockDataController(IStockDataService stockDataService, IStockHistoryDataService stockHistoryDataService, IStockProfitDataService stockProfitDataService) {
        this.stockDataService = stockDataService;
        this.stockHistoryDataService = stockHistoryDataService;
        this.stockProfitDataService = stockProfitDataService;
    }

    @GetMapping("/getNewStockData")
    @ApiOperation("获取最新持仓")
    public ResultVo getNewStockData() {
        return ResultVo.success(stockDataService.getNewStockData());
    }

    @GetMapping("/getHistoryData")
    @ApiOperation("获取历史数据")
    public ResultVo getHistoryData() {
        return ResultVo.success(stockHistoryDataService.getHistoryData());
    }

    @GetMapping("/getHistoryTradeData")
    @ApiOperation("获取历史交易数据")
    public ResultVo getHistoryTradeData() {
        return ResultVo.success(stockHistoryDataService.getHistoryTradeData());
    }

    @GetMapping("/getStockProfitData")
    @ApiOperation("获取股票收益数据")
    public ResultVo getStockProfitData(@RequestParam(required = false) String beginDate,
                                       @RequestParam(required = false) String endDate) {
        return ResultVo.success(stockProfitDataService.getStockProfitData(beginDate,endDate));
    }

    @GetMapping("/getTotalProfitRate")
    @ApiOperation("获取总收益率")
    public ResultVo getTotalProfitRate(@RequestParam(required = false) String beginDate,
                                       @RequestParam(required = false) String endDate) {
        return ResultVo.success(stockProfitDataService.getTotalProfitRate(beginDate,endDate));
    }

    @GetMapping("/getAiStockData")
    @ApiOperation("智能选股")
    public ResultVo getAiStockData(@RequestParam String queryStr) {
        return ResultVo.success(stockProfitDataService.getAiStockData(queryStr));
    }

}
